/*
 * ViewTenantForm.java
 *
 * Created on __DATE__, __TIME__
 */

package edu.washburn.cm333.project.gui;

import java.util.List;

import javax.persistence.EntityManager;

import edu.washburn.cm333.project.entities.PropertyManager;
import edu.washburn.cm333.project.entities.Tenant;

/**
 *
 * @author  __USER__
 */
public class ViewTenantForm extends javax.swing.JFrame {

	/** Creates new form ViewTenantForm */
	public ViewTenantForm() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		lblSelectTenant = new javax.swing.JLabel();
		EntityManager em = PropertyManager.getEntityManager();
		List<Tenant> tenantList = em.createQuery("select t from Tenant t",
				Tenant.class).getResultList();
		jComboBox1 = new Java2sAutoComboBox(tenantList);
		btnExit = new javax.swing.JButton();
		lblFName = new javax.swing.JLabel();
		lblDispFName = new javax.swing.JLabel();
		lblLName = new javax.swing.JLabel();
		lblDispLName = new javax.swing.JLabel();
		lblSSN = new javax.swing.JLabel();
		lblDispSSN = new javax.swing.JLabel();

		setTitle("View Tenant");
		setName("ViewTenantForm");

		lblSelectTenant.setText("Select Tenant");

		jComboBox1.setSelectedIndex(-1);
		jComboBox1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jComboBox1ActionPerformed(evt);
			}
		});

		btnExit.setText("Exit");
		btnExit.setToolTipText("");
		btnExit.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btnExitActionPerformed(evt);
			}
		});

		lblFName.setText("First Name");

		lblDispFName.setToolTipText("");

		lblLName.setText("Last Name");

		lblSSN.setText("SSN");
		lblSSN.setToolTipText("");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(71, 71,
																		71)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						lblSelectTenant,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						88,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						lblFName)
																				.addComponent(
																						lblLName)
																				.addComponent(
																						lblSSN))
																.addGap(88, 88,
																		88)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.TRAILING)
																				.addComponent(
																						lblDispFName)
																				.addComponent(
																						jComboBox1,
																						javax.swing.GroupLayout.PREFERRED_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.PREFERRED_SIZE)
																				.addComponent(
																						lblDispLName)
																				.addComponent(
																						lblDispSSN)))
												.addGroup(
														layout.createSequentialGroup()
																.addGap(169,
																		169,
																		169)
																.addComponent(
																		btnExit)))
								.addContainerGap(123, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(43, 43, 43)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblSelectTenant)
												.addComponent(
														jComboBox1,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(39, 39, 39)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblFName)
												.addComponent(lblDispFName))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblLName)
												.addComponent(lblDispLName))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(lblSSN)
												.addComponent(lblDispSSN))
								.addGap(34, 34, 34).addComponent(btnExit)
								.addContainerGap(34, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
		Object a = ((Java2sAutoComboBox) jComboBox1).autoTextFieldEditor
				.getItem();
		if (a instanceof Tenant) {
			lblDispFName.setText(((Tenant) a).getFName());
			lblDispLName.setText(((Tenant) a).getLName());
			lblDispSSN.setText(((Tenant) a).getTaxId());
		}
	}

	private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {
		this.setVisible(false);
	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new ViewTenantForm().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton btnExit;
	private javax.swing.JComboBox jComboBox1;
	private javax.swing.JLabel lblDispFName;
	private javax.swing.JLabel lblDispLName;
	private javax.swing.JLabel lblDispSSN;
	private javax.swing.JLabel lblFName;
	private javax.swing.JLabel lblLName;
	private javax.swing.JLabel lblSSN;
	private javax.swing.JLabel lblSelectTenant;
	// End of variables declaration//GEN-END:variables

}